<?php
namespace app\common\model;
/**
 * Created by PhpStorm.
 * User: junyv
 * Date: 2016/9/18
 * Time: 10:36
 */
class WeixinMsgReplay extends \think\Model
{
    protected $autoWriteTimestamp = true;
    protected $insert = ['ordid'];
    protected function setDataAttr($data){
        if(!empty($data) && is_array($data) && empty($data['Url'])){
            foreach($data as $key=>&$v){
                if(is_array($v)){
                    $v['Url'] = $this->getUrl($v['aid'],$v['model']);//url($v['model'].'/detail@'.$this->getDomain(),['id'=>$v['aid']]);
                     if(strpos($v['PicUrl'],'http://')===FALSE){
                         $v['PicUrl'] = 'http://'.config('domain.mobile').$v['PicUrl'];
                     }
                    unset($v['model'],$v['aid']);
                }else{
                    $data['Url'] = $this->getUrl($this->aid,$this->model);//url($this->model.'/detail@'.$this->getDomain(),['id'=>$this->aid]);
                    if(strpos($data['PicUrl'],'http://')===FALSE){
                        $data['PicUrl'] = 'http://'.config('domain.mobile').$data['PicUrl'];
                    }
                    unset($data['model'],$data['aid']);
                    break;
                }
            }
        }else{
            if(isset($data['PicUrl']) && strpos($data['PicUrl'],'http://')===FALSE){
                $data['PicUrl'] = 'http://'.config('domain.mobile').$data['PicUrl'];
            }
        }
        return serialize($data);
    }
    protected function getDataAttr($data){
        return unserialize($data);
    }
    protected function setOrdidAttr(){
        if(isset($this->model)){
            switch($this->model){
                case 'house':
                    $ordid = 10;
                    break;
                case 'activity' :
                    $ordid = 5;
                    break;
                case 'article' :
                    $ordid = 3;
                    break;
                default:
                    $ordid = 0;
            }
        }else{
            $ordid = 0;
        }

        return $ordid;
    }
    public function getModel(){
        $data = [
             'article' => '文章',
            'activity' => '活动',
            'house'    => '楼盘'
        ];
        return $data;
    }
    private function getUrl($id,$model){
        $config = [
            'article' => '/news/',
            'activity'=> '/huodong/',
            'house'   => '/loupan/'
        ];
        $url = 'http://'.$this->getDomain().$config[$model].$id.'.html';
        return $url;
    }
    private function getDomain(){
       return config('domain.mobile');
    }
}